Skip to content

Drive Win32 composition effects from RenderTargetSceneInfo on the render thread - #22114

Open
kekekeks wants to merge 3 commits into
mainfrom
feature/render-thread-transparency
Open

Drive Win32 composition effects from RenderTargetSceneInfo on the render thread#22114
kekekeks wants to merge 3 commits into
mainfrom
feature/render-thread-transparency

Conversation

@kekekeks

Copy link
Copy Markdown
Member

Right now we can present frames in a torn state:

  1. frame gets committed and scheduled for render with some transparency level enabled (and assumes semi-transparent background)
  2. UI thread flips transparency hint to non-transparent or switches theme variant from light to dark, it's propagated to render surfaces, WinUI visuals immediately get updated (for frame -1 that's currently on-screen), new frame with correct content is committed
  3. render thread renders a new frame with transparency level and theme variant from (1)
  4. render thread finally gets a correct matching frame from (2)

The PR makes win32 backend to derive state from RenderTargetSceneInfo passed by compositor that now also holds the theme variant hint needed for mica theme selection. Since theme variant isn't something we care about across platforms, it's carried via new opaque platform-speciic RenderTargetSceneInfo field.

…der thread

Adds an opaque CompositionTarget.TopLevelSpecificSceneInfo bag (with the
corresponding ITopLevelImpl property and changed callback) that travels
through the composition transport and arrives in RenderTargetSceneInfo.
The Win32 backend publishes the theme variant through it.

The WinUI/DComp composited window render targets now apply blur/mica
visual state in BeginDraw, based on the transparency level and theme
variant from the scene info, inside the same transaction as the frame.
The UI-thread ICompositionEffectsSurface.SetBlur path is removed, so
effect changes can no longer race the render thread and produce frames
with mismatched alpha mode and blur state.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TrfgSxPjyUvvKsAPFZoLR1
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0069232-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Comment on lines +36 to +37
// TopLevelSpecificSceneInfo is an opaque immutable object provided by the platform's
// ITopLevelImpl.TopLevelSpecificSceneInfo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use xml docs here. As it's currently written, it both explains a specific property and doesn't do it properly.

// TopLevelSpecificSceneInfo is an opaque immutable object provided by the platform's
// ITopLevelImpl.TopLevelSpecificSceneInfo.
public record struct RenderTargetSceneInfo(PixelSize Size, double Scaling, Size LogicalSize,
CompositionTransparencyLevel TransparencyLevel, object? TopLevelSpecificSceneInfo = null)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransparencyLevel is also a TopLevelSpecificSceneInfo of sorts, no. Would it make sense to reduce parameters? It's a private API as I can see

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PlatformThemeVariant specifically is a something that we have in every backend. It's just that only Win32 reads surface it (same for TransparencyLevel I think?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So whole SceneInfo could be a record class, not an object, with platform specific overrides (if necessary)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume WinUICompositionBackdropCornerRadius could be a win-specific top-level scene info in the future (not for this PR obv)

// TopLevelSpecificSceneInfo is an opaque immutable object provided by the platform's
// ITopLevelImpl.TopLevelSpecificSceneInfo.
public record struct RenderTargetSceneInfo(PixelSize Size, double Scaling, Size LogicalSize,
CompositionTransparencyLevel TransparencyLevel, object? TopLevelSpecificSceneInfo = null)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TopLevelSpecificSceneInfo -> TopLevelSceneInfo? I know it's a private API but still could be less verbose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-rendering backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch bug os-windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants